/*
 * CalendarTimePanel.java
 *
 * Created on 06 May 2004, 04:07
 */

package com.velocityme.client.gui.calendar;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author  Robert
 */
public class CalendarTimePanel extends javax.swing.JPanel {
    
    /** Creates new form CalendarTimePanel */
    public CalendarTimePanel() {
        initComponents();
        for (int h = 0; h < 24; h++)
            jComboBoxHours.addItem(Integer.toString(h));
        for (int m = 0; m < 60; m+=5)
            jComboBoxMinutes.addItem(Integer.toString(m));
    }
    
    public void setDate(Date p_date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(p_date);
        int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
        jComboBoxHours.setSelectedIndex(hourOfDay);
        int minute = calendar.get(Calendar.MINUTE);
        jComboBoxMinutes.setSelectedIndex(minute/5);
    }
    
    public Date getDate() throws ParseException {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(jComboBoxHours.getSelectedItem().toString()));
        calendar.set(Calendar.MINUTE, Integer.parseInt(jComboBoxMinutes.getSelectedItem().toString()));
        return calendar.getTime();
    }
    
    public void setEnabled(boolean p_enabled) {
        jComboBoxHours.setEnabled(p_enabled);
        jComboBoxMinutes.setEnabled(p_enabled);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jComboBoxHours = new javax.swing.JComboBox();
        jLabelHours = new javax.swing.JLabel();
        jComboBoxMinutes = new javax.swing.JComboBox();

        setLayout(new java.awt.GridBagLayout());

        jComboBoxHours.setMaximumRowCount(24);
        jComboBoxHours.setPreferredSize(new java.awt.Dimension(44, 19));
        add(jComboBoxHours, new java.awt.GridBagConstraints());

        jLabelHours.setText("h:");
        add(jLabelHours, new java.awt.GridBagConstraints());

        jComboBoxMinutes.setMaximumRowCount(12);
        jComboBoxMinutes.setPreferredSize(new java.awt.Dimension(44, 19));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        add(jComboBoxMinutes, gridBagConstraints);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBoxHours;
    private javax.swing.JComboBox jComboBoxMinutes;
    private javax.swing.JLabel jLabelHours;
    // End of variables declaration//GEN-END:variables
    
}
